--
-- Author:      feilong
-- DateTime:    2019-10-30 10:59:15
-- Description: 节点中用户管理

local User = import("gate.User")
local UserManager = class("UserManager")

function UserManager:ctor()
    self.user_list = {}
end

function UserManager:start()
    self.node_message = node_message
end

function UserManager:addUser(user)
	local user_id = user:getUserId()
    local old_user = self.user_list[user_id]
    self.user_list[user_id] = user
    return old_user
end

function UserManager:removeUser(user_id)
    if not self.user_list[user_id] then 
    	return false
    end
    self.user_list[user_id] = nil
end

function UserManager:getUser(user_id)
    return self.user_list[user_id]
end

function UserManager:getUserList()
    return self.user_list
end

function UserManager:createUser(user_id)
    --给user分配server 
    local server_user = self.node_message:callDbRedis(user_id, "hgetall", "server_user:"..user_id)
    server_user.user_id = nil        
    local user = User.new(user_id)
    user:setData(server_user)
    self:addUser(user)
end





















return UserManager